home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / c_toolbx.arc / CURVE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-30  |  1.5 KB  |  62 lines

  1. /* curvr.c - assigns pass/fail grades on a curve system */
  2. #include "stdio.h"
  3.  
  4. typedef struct            /* definition of student data t  */
  5.  {
  6.   char name[30] ;
  7.   int grade ;
  8.  } STUDENT  ;
  9. main()
  10.  {
  11.    STUDENT class[400]  ;    /* student data for entire class  */
  12.    int ns  ;            /* count of students in the class */
  13.             /* collect list of students and number grades */
  14.    int    i , cutoff  ;
  15.  
  16.    printf(" Number of Students: \n") ;
  17.    scanf("%d",&ns)  ;
  18.    printf(" Enter name and grade for each student  \n") ;
  19.    for( i=0 ; i < ns ; i=i+1)
  20.      { scanf("%s %d",class[i].name, class[i].grade) ; }
  21.  
  22.    sortclass(class,ns) ;
  23.    cutoff = (ns * 7) / 10 - 1  ;
  24.    printf("\n") ;
  25.    for( i=0 ; i < ns ; i=i+1)
  26.      { printf("%-6s %3d", class[i].name, class[i].grade)  ;
  27.        if( i <= cutoff )
  28.           printf(" Pass \n")  ;
  29.      else printf(" Fail \n")  ;
  30.      }
  31.  }
  32.  
  33. sortclass(st,nst)    /* sort by numeric grade  */
  34.  STUDENT st[] ;     /* array of student data structures  */
  35.  int     nst  ;     /* number of students  */
  36.  {
  37.     int  i , j , pick  ;
  38.  
  39.     for( i=0 ; i < (nst-1) ;i = i+1 )
  40.       { pick = j  ;
  41.     for( j=i+1 ; j < nst ; j=j+1)
  42.       { if( st[j].grade > st[pick].grade )
  43.         pick = j ;
  44.       }
  45.     swap(& st[i] , & st[pick] )  ;
  46.       }
  47.  }
  48.  
  49. swap(ps1,ps2)
  50.  STUDENT  *ps1    ;
  51.  STUDENT  *ps2    ;
  52.  {
  53.    STUDENT temp ;
  54.  
  55.    strcpy(temp.name, ps1->name ) ; temp.grade = ps1->grade  ;
  56.    strcpy(ps1->name,ps2->name) ; ps1->grade = ps2->grade  ;
  57.    strcpy(ps2->name,temp.name) ; ps2->grade = temp.grade  ;
  58.  }
  59.  
  60.  
  61.  
  62.